package com.kehao.leetcode.jzoffer;

import org.junit.Test;

import java.util.Locale;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/22 17:15
 */
public class JZSolution018 {
    public boolean validPalindrome(String s) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if((c >='a'&& c <='z')||(c >='A'&& c <='Z')||(c >='0'&& c <='9')){
                sb.append(c);
            }
        }
        s = sb.toString().toLowerCase();
        int length = s.length();
        for (int i = 0; i < length / 2; i++) {
            if(s.charAt(i)!=s.charAt(length-1-i)){
                return false;
            }
        }
        return true;
    }

    @Test
    public void test01(){
        System.out.println(validPalindrome("abca"));
    }
}
